package com.eric.windows.imgDispose;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.eric.windows.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.Random;

@EActivity(R.layout.activity_waterfall_test)
public class WaterfallTestActivity extends Activity {
    private static int IMG_COUNT = 5;
    @ViewById(R.id.waterfallLayout)
    WaterfallLayout waterfallLayout;

    @ViewById(R.id.txt_wf)
    TextView textView;


    @AfterViews
    public void initData(){
        addView();
    }

    @Click(R.id.add_btn_waterfall)
    public void onClick(){
        addView();
    }

    public void addView() {
        Random random = new Random();
        Integer num = Math.abs(random.nextInt());
        WaterfallLayout.LayoutParams layoutParams = new WaterfallLayout.LayoutParams(WaterfallLayout.LayoutParams.WRAP_CONTENT,
                WaterfallLayout.LayoutParams.WRAP_CONTENT);
        ImageView imageView = new ImageView(this);
        if (num % IMG_COUNT == 0) {
            imageView.setImageResource(R.mipmap.pic_1);
        } else if (num % IMG_COUNT == 1) {
            imageView.setImageResource(R.mipmap.pic_2);
        } else if (num % IMG_COUNT == 2) {
            imageView.setImageResource(R.mipmap.pic_3);
        } else if (num % IMG_COUNT == 3) {
            imageView.setImageResource(R.mipmap.pic_4);
        } else if (num % IMG_COUNT == 4) {
            imageView.setImageResource(R.mipmap.pic_5);
        }
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        waterfallLayout.addView(imageView, layoutParams);

        waterfallLayout.setOnItemClickListener(new WaterfallLayout.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int index) {
                Toast.makeText(WaterfallTestActivity.this, "item=" + index, Toast.LENGTH_SHORT).show();
            }
        });

//
//        //获取View自身可见的坐标区域
//        Rect rect = new Rect();
//        textView.getLocalVisibleRect(rect);
//        Log.e("LocalVisibleRect=====>",rect.toString());
//        //获取View在屏幕绝对坐标系中的可视区域
//        textView.getGlobalVisibleRect(rect);
//        Log.e("GlobalVisibleRect=====>",rect.toString());
//
//        int[] location = new int[2];
//        //坐标是相对整个屏幕而言，Y坐标为View左上角到屏幕顶部的距离
//        textView.getLocationOnScreen(location);
//        Log.e("LocationOnScreen=====>",location[0] + "," + location[1]);
//        //
//        textView.getLocationInWindow(location);
//        Log.e("LocationInWindow=====>",location[0] + "," + location[1]);
//
//        textView.offsetLeftAndRight(500);
//
//        //获取View自身可见的坐标区域
//        textView.getLocalVisibleRect(rect);
//        Log.e("LocalVisibleRect移动===>",rect.toString());
//        //获取View在屏幕绝对坐标系中的可视区域
//        textView.getGlobalVisibleRect(rect);
//        Log.e("GlobalVisibleRect移动===>",rect.toString());
//
//        //坐标是相对整个屏幕而言，Y坐标为View左上角到屏幕顶部的距离
//        textView.getLocationOnScreen(location);
//        Log.e("LocationOnScreen移动===>",location[0] + "," + location[1]);
//        //
//        textView.getLocationInWindow(location);
//        Log.e("LocationInWindow移动===>",location[0] + "," + location[1]);
//
////        textView.scrollTo(200,0);
//
//        imageView.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                Log.e("绝对坐标===》","x：" + event.getRawX());
//                Log.e("绝对坐标===》","y：" + event.getRawY());
//                Log.e("相对坐标===》","x：" + event.getX());
//                Log.e("相对坐标===》","y：" + event.getY());
//                return false;
//            }
//        });

    }



}


